/*
 *  Copyright (C) 2010 Jesus Navalon i Pastor <jnavalon at redhermes dot net>
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * pn_TB_AddHost.java
 *
 * Created on 01/11/2010, 23:20:40
 */

package kuasar.plugin.vmcreator.gui.tooltasks.AddHost;

import java.util.HashMap;
import javax.swing.JPanel;
import kuasar.plugin.Intercom.GUI;
import kuasar.plugin.vmcreator.gui.pn_Main;

/**
 *
 * @author Jesus Navalon i Pastor <jnavalon at redhermes dot net>
 */
public class pn_TB_AddHost extends javax.swing.JPanel {

    /** Creates new form pn_TB_AddHost */

    protected HashMap<String,Object> data = null;
    protected pn_Main panel;
    protected int showing=0;
    protected String name=null;
    protected String filename = null;
    public pn_TB_AddHost(pn_Main panel) {
        Load(panel, new HashMap<String,Object>());
        hideLevels();
    }
    public pn_TB_AddHost(pn_Main panel, HashMap<String,Object> map, String name, String filename){
        this.name=name;
        this.filename = filename;
        Load(panel,map);
    }

    private void Load(pn_Main panel, HashMap<String,Object> map){
        this.panel=panel;
        data = map;
        initComponents();
        GUI.loadPlugin(new pn_AddHV(this));
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        lbl_level0 = new javax.swing.JLabel();
        lbl_sep0 = new javax.swing.JLabel();
        lbl_level1 = new javax.swing.JLabel();
        lbl_sep1 = new javax.swing.JLabel();
        lbl_level2 = new javax.swing.JLabel();
        lbl_sep2 = new javax.swing.JLabel();
        lbl_level3 = new javax.swing.JLabel();
        lbl_sep3 = new javax.swing.JLabel();
        lbl_level4 = new javax.swing.JLabel();

        setMaximumSize(new java.awt.Dimension(330, 60));
        setOpaque(false);
        setPreferredSize(new java.awt.Dimension(330, 60));

        jToolBar1.setBorder(null);
        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setOpaque(false);
        jToolBar1.setPreferredSize(new java.awt.Dimension(340, 48));
        jToolBar1.add(jSeparator1);

        lbl_level0.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/vmcreator/icons/hvs.png"))); // NOI18N
        lbl_level0.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lbl_level0.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                lbl_level0MouseReleased(evt);
            }
        });
        jToolBar1.add(lbl_level0);

        lbl_sep0.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/vmcreator/icons/next-separate.png"))); // NOI18N
        jToolBar1.add(lbl_sep0);

        lbl_level1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/vmcreator/icons/noGPL/os.png"))); // NOI18N
        lbl_level1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lbl_level1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                lbl_level1MouseReleased(evt);
            }
        });
        jToolBar1.add(lbl_level1);

        lbl_sep1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/vmcreator/icons/next-separate.png"))); // NOI18N
        jToolBar1.add(lbl_sep1);

        lbl_level2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/vmcreator/icons/media.png"))); // NOI18N
        lbl_level2.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lbl_level2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                lbl_level2MouseReleased(evt);
            }
        });
        jToolBar1.add(lbl_level2);

        lbl_sep2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/vmcreator/icons/next-separate.png"))); // NOI18N
        jToolBar1.add(lbl_sep2);

        lbl_level3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/vmcreator/icons/net.png"))); // NOI18N
        lbl_level3.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lbl_level3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                lbl_level3MouseReleased(evt);
            }
        });
        jToolBar1.add(lbl_level3);

        lbl_sep3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/vmcreator/icons/next-separate.png"))); // NOI18N
        jToolBar1.add(lbl_sep3);

        lbl_level4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/vmcreator/icons/legalmoves.png"))); // NOI18N
        lbl_level4.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lbl_level4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                lbl_level4MouseReleased(evt);
            }
        });
        jToolBar1.add(lbl_level4);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void lbl_level0MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbl_level0MouseReleased
        loadPanel(0);
    }//GEN-LAST:event_lbl_level0MouseReleased

    private void lbl_level1MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbl_level1MouseReleased
        loadPanel(1);
    }//GEN-LAST:event_lbl_level1MouseReleased

    private void lbl_level2MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbl_level2MouseReleased
        loadPanel(2);
    }//GEN-LAST:event_lbl_level2MouseReleased

    private void lbl_level3MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbl_level3MouseReleased
        loadPanel(3);
    }//GEN-LAST:event_lbl_level3MouseReleased

    private void lbl_level4MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lbl_level4MouseReleased
        loadPanel(4);
    }//GEN-LAST:event_lbl_level4MouseReleased

    protected void loadPanel(int level){
        GUI.loadPlugin(getPanel(level));
        GUI.updateUI();
        showing = level;
    }
    
    private void hideLevels(){
        lbl_level1.setVisible(false);
        lbl_level2.setVisible(false);
        lbl_level3.setVisible(false);
        lbl_level3.setVisible(false);
        lbl_level4.setVisible(false);
        lbl_sep0.setVisible(false);
        lbl_sep1.setVisible(false);
        lbl_sep2.setVisible(false);
        lbl_sep3.setVisible(false);
        lbl_sep3.setVisible(false);
    }

    private void showLevels(int level){
        switch(level){
            case 1:
                lbl_level1.setVisible(true);
                lbl_sep0.setVisible(true);
                break;
            case 2:
                lbl_level2.setVisible(true);
                lbl_sep1.setVisible(true);
                break;
            case 3:
                lbl_level3.setVisible(true);
                lbl_sep2.setVisible(true);
                break;
            case 4:
                lbl_level4.setVisible(true);
                lbl_sep3.setVisible(true);
                break;
            default:
                return;
        }
    }

    private JPanel getPanel(int index){
        switch(index){
            case 0:
                return new pn_AddHV(this);
            case 1:
                return new pn_AddOS(this);
            case 2:
                return new pn_SetFeatures(this);
            case 3:
                return new pn_AddNetwork(this);
            case 4:
                return new pn_Summary(this);
            default:
                return null;
        }
    }
    
    protected void next(){
        JPanel aux = getPanel(showing +1);
        if(aux == null)
            return;
        showing++;
        GUI.loadPlugin(aux);
        GUI.updateUI();
        showLevels(showing);

    }

    protected void previous(){
        if(showing-1 ==-1){
            return;
        }
        showing--;
        GUI.loadPlugin(getPanel(showing));
        GUI.updateUI();
    }

    protected void exit(){
        GUI.loadPlugin(panel);
        GUI.unLoadToolBar();
        GUI.loadToolBar(panel.tb);
        GUI.updateUI();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JLabel lbl_level0;
    private javax.swing.JLabel lbl_level1;
    private javax.swing.JLabel lbl_level2;
    private javax.swing.JLabel lbl_level3;
    private javax.swing.JLabel lbl_level4;
    private javax.swing.JLabel lbl_sep0;
    private javax.swing.JLabel lbl_sep1;
    private javax.swing.JLabel lbl_sep2;
    private javax.swing.JLabel lbl_sep3;
    // End of variables declaration//GEN-END:variables

}
